//
//  TIMChatData.m
//  NCChatUI_Example
//
//  Created by LINAICAI on 2018/4/16.
//  Copyright © 2018年 LINAICAI. All rights reserved.
//

#import "TIMChatData.h"

@implementation TIMChatData
- (NSMutableArray<NCChatMessage *> *)msgs{
    if (!_msgs) {
        _msgs = [NSMutableArray<NCChatMessage *> new];
    }
    return _msgs;
}
///获取所有聊天消息
- (NSMutableArray<NCChatMessage*> *)messages{
    return self.msgs;
}
///添加聊天消息
- (void)addMessages:(NCChatMessage *)message complete:(void(^)(void))complete{
    [self.msgs addObject:message];
    if (complete) {
        complete();
    }
}
///加载更多聊天记录
- (void)loadMoreMessages:(void(^)(NSUInteger))complete{
    [self.msgs insertObject:[NCChatTextMessage messageWith:@"更多聊天记录来了" senderId:@"123456" date:[NSDate date]] atIndex:0];
    [self.msgs insertObject:[NCChatTextMessage messageWith:@"更多聊天记录来了" senderId:@"123456" date:[NSDate date]] atIndex:0];
    [self.msgs insertObject:[NCChatTextMessage messageWith:@"更多聊天记录来了" senderId:@"123456" date:[NSDate date]] atIndex:0];
    [self.msgs insertObject:[NCChatTextMessage messageWith:@"更多聊天记录来了" senderId:@"123456" date:[NSDate date]] atIndex:0];

    if (complete) {
        complete(4);
    }
}
///预加载聊天记录
- (void)proLoadMessages:(void(^)(void))complete{

    ///文本消息
    [self.msgs addObject:[NCChatTextMessage messageWith:@"新华网北京4月13日电 13日上午，习近平总书记在海口市参观了海南建省办经济特区30周年成就展，对30年来特别是党的十八大以来海南经济社会发展成就给予肯定。他指出，贯彻党中央精神不是喊口号，要结合当地实际、经过深入调研形成符合党中央精神的一系列具体举措，并在实施中早见成效、大见成效。" senderId:@"123456" date:[NSDate date]]];
    [self.msgs addObject:[NCChatTextMessage messageWith:@"www.baidu.com,王总你好文件已发送，请查收" senderId:@"123456" date:[NSDate date]]];
    [self.msgs addObject:[NCChatTextMessage messageWith:@"报价清单发我一遍，谢谢" senderId:@"123456" date:[NSDate date]]];
    [self.msgs addObject:[NCChatTextMessage messageWith:@"www.baidu.com王总你好，文件已发送，请查收" senderId:@"000000" date:[NSDate date]]];
    [self.msgs addObject:[NCChatTextMessage messageWith:@"报价清单发我一遍，谢谢报价清单发我一遍谢谢报价清单发我一遍，谢谢" senderId:@"000000" date:[NSDate date]]];
    //系统消息
    [self.msgs addObject:[NCChatSystemMessage  messageWith:@"新华网北京4月13日电 13日上午，习近平总书记在海口市参观了海南建省办经济特区30周年成就展，对30年来特别是党的十八大以来海南经济社会发展成就给予肯定。他指出，贯彻党中央精神不是喊口号，要结合当地实际、经过深入调研形成符合党中央精神的一系列具体举措，并在实施中早见成效、大见成效。" date:[NSDate date]]];
    
    [self.msgs addObject:[NCChatSystemMessage  messageWith:@"Yet选择直接进入定标通知" date:[NSDate date]]];
    [self.msgs addObject:[NCChatSystemMessage  messageWith:@"操作提示:招标人已完成定标筛选\n总结:123123" date:[NSDate date]]];
    
    
    NCChatCustomMessage *message = [NCChatCustomMessage messageWith:@"为提高您在线议标的工作效益，建议您查阅我们提供的发包采购操作指引"];
    message.isGuide = YES;
    [self.msgs addObject:message];
    
    [self.msgs addObject:[NCChatCustomMessage messageWith:@"Yet选择直接进入定标通知"]];
    if (complete) {
        complete();
    }
   
}
///根据用户id获取用户名和用户头像
- (NCChatUser *)userWithSenderId:(NSString *)senderId{
    if ([senderId isEqualToString:@"123456"]) {
        NCChatUser *user = [[NCChatUser alloc]initUserName:@"李柰财" userId:@"123456" userAvator:@"https://cdn.v2ex.com/avatar/4e13/cab9/48493_large.png?m=1430968523"];
        return user;
    }
    else{
        NCChatUser *user = [[NCChatUser alloc]initUserName:@"其他人" userId:@"000000" userAvator:@"https://cdn.v2ex.com/avatar/4e13/cab9/48493_large.png?m=1430968523"];
        return user;
    }
    
}
///删除某条信息
- (void)delectMessage:(NCChatMessage *)message complete:(void (^)(void))complete{
    [self.msgs removeObject:message];
    if (complete) {
        complete();
    }
}
@end
